﻿@model ConferenceNewsListModel
@{
	ViewBag.Title = Resources.ConferenceNewsList + ConstValues.strDash + ViewBag.ConferenceName;
}
<div id="menuBar" style="height:35px;">
	<div style="float: left; padding: 5px 5px; font-weight: bold; text-align: left;">
		@Resources.NewsListName：<input id="selNewsListName" class="easyui-textbox" style="height:27px; width:200px;" />&nbsp;&nbsp;
		<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" onclick="searchData();">@Resources.Search</a>&nbsp;&nbsp;
		@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceNewsList, RoleType.添加))
		{
			<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-add" onclick="addData();" plain="true">@Resources.Create</a>
		}
	</div>
	<div class="clear"></div>
</div>
<div id="dataGrid"></div>

@section bodyParts {
<div id="detailWindow" class="easyui-window"
	title="@Resources.ConferenceNewsList" data-options="closed:true,minimizable:false,maximizable:false,iconCls:'icon-save'"
	style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="detailWindowTitle" class="tit01">@Resources.Create</h3>
			<form id="frmDetail" method="post" enctype="multipart/form-data">
				@Html.AntiForgeryToken()
				<table width="100%" height="100%" id="tblDetail" cellpadding="0" cellspacing="1" border="0" class="tastyle01">
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.ConferenceName：</td>
						<td style="text-align: left;" class="w2 c2">
							<input type="hidden" id="hidID" name="Id" />
							<input type="hidden" id="hidConferenceId" name="conferenceId" />
							<input id="txtConferenceName" disabled class="easyui-textbox" style="height:27px; width:300px;" value="@ViewBag.ConferenceName">
						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.NewsListName：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="txtNewsListName" name="newsListName" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true,validType:['length[1,100]']">
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.NewsListPosition：</td>
						<td style="text-align: left;" class="w2 c4">
							<select class="easyui-combobox" id="txtNewsListPosition" name="newsListPosition" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'">
								<option value="@ConstValues.ConferenceModelStyle.Left">@Resources.Left</option>
								<option value="@ConstValues.ConferenceModelStyle.Right">@Resources.Right</option>
								<option value="@ConstValues.ConferenceModelStyle.Center">@Resources.Mid</option>
							</select>
						</td>
						<td style="text-align: right;" class="w1 c3">@Resources.NewsStyle：</td>
						<td style="text-align: left;" class="w2 c4">
							<select id="txtNewsStyle" name="newsStyle" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'">
								<option value="@ConstValues.NewsStyle.图标时摘">@Resources.PicTitleTimeAbstract</option>
								<option value="@ConstValues.NewsStyle.标">@Resources.NewsTitle</option>
								<option value="@ConstValues.NewsStyle.标时">@Resources.TitleAndTime</option>
								<option value="@ConstValues.NewsStyle.图">@Resources.NewsPic</option>
								<option value="@ConstValues.NewsStyle.图标">@Resources.PicAndTitle</option>
								<option value="@ConstValues.NewsStyle.正文">@Resources.NewsEssay</option>
							</select>
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.NewsListPic：</td>
						<td style="text-align: left;" class="w2 c2" colspan="3">
							<input id="txtNewsListPic" name="newsListPic" class="easyui-filebox" style="height:27px; width:840px;" data-options="prompt:'@Resources.ImportImg', buttonText:'@Resources.ChooseImg', accept: 'image/jpeg,image/png,image/gif'">
							<a href="javascript:void(0)" class="easyui-linkbutton" onclick='$("#txtNewsListPic").filebox("clear");'>@Resources.Clear</a>
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.Link：</td>
						<td style="text-align: left;" class="w2 c4" colspan="3">
							<input id="txtLink" name="link" class="easyui-textbox" style="height:27px; width:892px;" data-options="">
						</td>
					</tr>
					<tr>
						<td style="text-align: right; " class="w1 c3">@Resources.BackgroundColor：</td>
						<td style="text-align: left;" class="w2 c4">
							<input type="color" name="BackgroundColor" id="BackgroundColor" list="defaultColor" />
							<datalist id="defaultColor">
								<option>#c00000</option>
								<option>#fc0000</option>
								<option>#fcc000</option>
								<option>#fcff00</option>
								<option>#92d050</option>
								<option>#00b050</option>
								<option>#00b0f0</option>
								<option>#0070c0</option>
								<option>#002060</option>
								<option>#7030a0</option>
							</datalist>
						</td>
						<td style="text-align: right; " class="w1 c3">@Resources.BackgroundOpacity：</td>
						<td style="text-align: left;" class="w2 c4">
							<select id="BackgroundOpacity" name="BackgroundOpacity" class="easyui-combobox" style="height:27px; width:100px;" data-options="editable:false,panelHeight:'auto'">
								<option value="0">0%</option>
								<option value="0.1">10%</option>
								<option value="0.2">20%</option>
								<option value="0.3">30%</option>
								<option value="0.4">40%</option>
								<option value="0.5">50%</option>
								<option value="0.6">60%</option>
								<option value="0.7">70%</option>
								<option value="0.8">80%</option>
								<option value="0.9">90%</option>
								<option value="1">100%</option>
							</select>
						</td>
					</tr>
					<tr>
						<td style="text-align: right; " class="w1 c1">@Resources.FontSize：</td>
						<td style="text-align: left;" class="w2 c2">
							<select id="FontSize" name="FontSize" class="easyui-combobox" style="height:27px; width:100px;" data-options="editable:false,panelHeight:'200'"></select>
						</td>
						<td style="text-align: right; " class="w1 c1">@Resources.FontWeight：</td>
						<td style="text-align: left;" class="w2 c2">
							<select id="FontWeight" name="FontWeight" class="easyui-combobox" style="height:27px; width:100px;" data-options="editable:false,panelHeight:'auto'">
								<option value="lighter">lighter</option>
								<option value="light">light</option>
								<option value="normal">normal</option>
								<option value="bold">bold</option>
								<option value="bolder">bolder</option>
							</select>
						</td>
					</tr>
					<tr>
						<td style="text-align: right; " class="w1 c3">@Resources.FontStyle：</td>
						<td style="text-align: left;" class="w2 c4">
							<select id="FontStyle" name="FontStyle" class="easyui-combobox" style="height:27px; width:100px;" data-options="editable:false,panelHeight:'auto'">
								<option value="normal">normal</option>
								<option value="italic">italic</option>
								<option value="oblique">oblique</option>
							</select>
						</td>
						<td style="text-align: right; " class="w1 c3">@Resources.FontColor：</td>
						<td style="text-align: left;" class="w2 c4">
							<input type="color" name="FontColor" id="FontColor" list="defaultColor" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right; " class="w1 c1">@Resources.LineColor：</td>
						<td style="text-align: left;" class="w2 c2">
							<input type="color" name="LineColor" id="LineColor" list="defaultColor" />
						</td>
						<td style="text-align: right; " class="w1 c1"></td>
						<td style="text-align: left;" class="w2 c2"></td>
					</tr>
					<tr>
						<td style="text-align: right; " class="w1 c3">@Resources.IsShowMore：</td>
						<td style="text-align: left;" class="w2 c4">
							<input type="checkbox" name="IsShowMore" id="IsShowMore" />
						</td>
						<td style="text-align: right; " class="w1 c3">@Resources.MoreColor：</td>
						<td style="text-align: left;" class="w2 c4">
							<input type="color" name="MoreColor" id="MoreColor" list="defaultColor" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.Status：</td>
						<td style="text-align: left;" class="w2 c2">
							<select id="ddlStatus" name="status" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'">
								<option value="@ConstValues.Status.正常">@Resources.Normal</option>
								<option value="@ConstValues.Status.暂停">@Resources.Pause</option>
							</select>
						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.Sort：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="txtSort" name="sort" class="easyui-numberbox" style="height:27px; width:300px;" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.Remark：</td>
						<td style="text-align: left;" class="w2 c4" colspan="3">
							<input id="txtRemark" name="remark" class="easyui-textbox" style="height:50px; width:892px;" data-options="multiline:true,validType:['length[1,1000]']" />
						</td>
					</tr>
				</table>
			</form>
			<div class="btnDiv">
				<input type="hidden" id="hdnWindowType" />
				<input type="button" class="gbtn" onclick="saveData();" value="@Resources.Save" />&nbsp;&nbsp;
				<input type="button" class="rbtn" onclick="$('#detailWindow').window('close');" value="@Resources.Cancel" />
			</div>					
		</div>
	</div>
</div>
}

@section Scripts {
<script>
	common.setCurrentMenu("ConferenceNewsList");
	common.setCurrentParentMenu("#menu_a5");

	$(function () {
		$("#hidConferenceId").val("@Model.ConferenceId");
		$("#selNewsListName").textbox("textbox").bind("keydown", function (e) {
			if (e.keyCode == 13) {
				searchData()
			}
		});

		$("#dataGrid").datagrid({
			url: "@Url.Action(nameof(ConferenceNewsListController.GetData),
					nameof(ConferenceNewsListController).GetControllerName(),new { ConferenceId = Model.ConferenceId })",
			method: "get",
			singleSelect: true,
			width: $(window).width() - 285,
			height: $(window).height() - 158,
			nowrap: false,
			pagination: true,
			pageSize: @ConstValues.DefaultGridRows,
			striped: true,
			toolbar: "#toolBar",
			pageSize: 100,
			pageList: [100, 200, 300, 400, 500],
			frozenColumns: [[
				{ field: "id", title: "@Resources.Id", align: "center", sortable: true, hidden:true, width: 50 },
				@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) ||
					Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceNewsList, RoleType.修改) ||
					Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceNewsList, RoleType.删除))
				{
					<text>
					{
					    	field: "operate", title: "@Resources.Operate", align: "center", width: 150,
					    	formatter: function(value, rec) {
					    		var strInfo = "";
					    		var tmp = rec.newsListName.replace(new RegExp("'",'g'),"’").replace(new RegExp('"','g'),"“");
					    		@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceNewsList, RoleType.修改))
							{
								<text>
					    			strInfo += "<a href='#' style='color:#66CDAA;font-weight:bold;text-decoration:underline;' onclick='editData(\""
									+ rec.id + "\")'>@Resources.Modify</a>";
					    			</text>
							}
					    		@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceNewsList, RoleType.删除))
							{
								<text>
					    			if (strInfo != "") {
					    				strInfo += "&nbsp;|&nbsp;";
					    			}
					    			strInfo += "<a href='#' style='color:#DC143C;font-weight:bold;text-decoration:underline;' onclick='deleteData(\""
									+ rec.id + "\",\"" + tmp + "\")'>@Resources.Delete</a>";
					    			</text>
							}
					    		return strInfo;
						}
					},
					</text>
				}
				{
					field: "newsListName", title: "@Resources.NewsListName", align: "center", sortable: true, width: 150,
	                		formatter: function (value, rec) {
	                			var conStr = ""
	                			if (rec.status == "@ConstValues.Status.正常") {
	                				if (rec.link	!="") {
	                					conStr += "<a href='" + rec.link + "' style='color:#1874CD;text-decoration:underline;' target='_blank'>" + value + "</a>  ";
	                					return conStr;
	                				} else {
	                					return value;
	                				}
	                			} else {
	                				return value;
	                			}
	                		}
				},
			]],
			columns: [[
				{
					field: "newsListPic", title: "@Resources.NewsListPic", align: "center", sortable: true, width: 100,
	                		formatter: function (value, rec) {
	                			if (value!=null && value != "") {
	                				var link = "";
	                				link +="<img id='aaa' style='height: 60px; width: 80px' src='@Url.Action(nameof(ConferenceNewsListController.ShowPic),nameof(ConferenceNewsListController).GetControllerName())"+"/"+ rec.id + "?random=" + Math.random() + "' />";
	                				return link;
	                			} else {
	                				return "@ConstValues.strHyphen@ConstValues.strHyphen"
	                			}
	                		}
				},
				{
					field: "newsListPosition", title: "@Resources.NewsListPosition", align: "center", sortable: true, width: 150,
	                		formatter: function(value, rec) {
	                			if (value=="@ConstValues.ConferenceModelStyle.Left" ) {
	                				return "@Resources.Left"
	                			} else if(value=="@ConstValues.ConferenceModelStyle.Center") {
	                				return "@Resources.Mid"
	                			} else if(value=="@ConstValues.ConferenceModelStyle.Right") {
	                				return "@Resources.Right"
	                			}
	                		}
				},
				{
					field: "newsStyle", title: "@Resources.NewsStyle", align: "center", sortable: true, width: 200,
	                		formatter: function(value, rec) {
	                			if (value=="@ConstValues.NewsStyle.图标时摘") {
	                				return "@Resources.PicTitleTimeAbstract"
	                			} else if (value=="@ConstValues.NewsStyle.标") {
	                				return "@Resources.NewsTitle"
	                			} else if (value=="@ConstValues.NewsStyle.标时") {
	                				return "@Resources.TitleAndTime"
	                			} else if (value=="@ConstValues.NewsStyle.图") {
	                				return "@Resources.NewsPic"
	                			} else if (value=="@ConstValues.NewsStyle.图标") {
	                				return "@Resources.PicAndTitle"
	                			} else if (value=="@ConstValues.NewsStyle.正文") {
	                				return "@Resources.NewsEssay"
	                			}
	                		}
				},
				{ field: "link", title: "@Resources.Link", align: "center", sortable: true, width: 300 },
				{
					field: "status", title: "@Resources.Status", align: "center", sortable: true, width: 100,
	                		formatter: function(value, rec) {
	                			if (value=="@ConstValues.Status.正常") {
	                				return "@Resources.Normal"
	                			} else {
	                				return "@Resources.Pause"
	                			}
	                		}
				},
				{ field: "sort", title: "@Resources.Sort", align: "center", sortable: true, width: 100 },
				{ field: "remark", title: "@Resources.Remark", align: "center", sortable: true, width: 250 },
				{ field: "creator", title: "@Resources.Creator", align: "center", sortable: true, width: 150 },
				{ field: "createIP", title: "@Resources.CreateIP", align: "center", sortable: true, width: 150 },
				{ field: "createDate", title: "@Resources.CreateDate", align: "center", sortable: true, width: 150 },
			]],
			onBeforeLoad: function(param) {
				param.random = Math.random();
				param.conferenceId = $("#hidConferenceId").val();
			}
		});

		$(window).resize(function () {
			$("#dataGrid").datagrid("resize", {
				width: $(window).width() - 285,
				height: $(window).height() - 110
			});
		});

		$("#detailWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: ($(window).height() - 676) * 0.5
		});

		$("#FontSize").combobox({
			url: "@Url.Action(nameof(UtilityController.GetFontSize), nameof(UtilityController).GetControllerName())",
			valueField: "id",
			textField: "name",
			editable: false,
		});
	});

	function deleteData(id,mailServer) {
		var confirmMessage = "@Resources.CfmDelete";
		confirmMessage = confirmMessage.replace(/\{0\}/g, mailServer);
		$.messager.confirm("@Resources.Delete", confirmMessage, function (r) {
			if (r) {
				$("#hidID").val(id);
				$.post("@Url.Action(nameof(ConferenceNewsListController.Delete),
						nameof(ConferenceNewsListController).GetControllerName(),new { ConferenceId = Model.ConferenceId })",
					$("#frmDetail").serialize(),
					function(data, textStatus, jqXHR) {
						if (data.result == "@ConstValues.AjaxFailResult") {
					    		common.showError(data.message);
						} else {
					    		common.showSuccess(data.message, true);
					    		$("#dataGrid").datagrid("reload");
						}
					}
				);
			}
		});
	};

	function addData() {
		$("#detailWindowTitle").text("@Resources.Create");
		$("#hdnWindowType").val("add");
		$("#txtNewsListName").textbox("setValue","");
		$("#txtNewsListPic").filebox("clear");
		$("#hidNewsListPic").val("");
		$("#txtNewsListPosition").combobox("setValue","");
		$("#txtNewsStyle").combobox("setValue","");
		$("#txtLink").textbox("setValue","");
		$("#BackgroundColor").val("#ffffff");
		$("#BackgroundOpacity").combobox("setValue", 1);
		$("#FontSize").combobox("setValue", "16px");
		$("#FontWeight").combobox("setValue", "normal");
		$("#FontStyle").combobox("setValue", "normal");
		$("#FontColor").val("#c30d23");
		$("#LineColor").val("#c30d23");
		$("#IsShowMore").prop("checked", true);
		$("#MoreColor").val("#8f8f8f");
		$("#ddlStatus").combobox("setValue", "@ConstValues.Status.正常");
		$("#txtSort").numberbox("setValue", @ConstValues.DefaultSort);
		$("#txtRemark").textbox("setValue","");

		$("#detailWindow").window("open");
	}

	function editData(id) {
		var url = "@Url.Action(nameof(ConferenceNewsListController.GetEditData),
				nameof(ConferenceNewsListController).GetControllerName())" + "/" + id;
		$.get(url, null, function (data, textStatus, jqXHR) {
			if (data.result == "@ConstValues.AjaxFailResult") {
				common.showError(data.message);
				$("#dataGrid").datagrid("reload");
			} else {
				$("#detailWindowTitle").text("@Resources.Modify");
				$("#hdnWindowType").val("edit");
				$("#hidID").val(id);
				$("#txtNewsListName").textbox("setValue",data.data.newsListName);
				$("#txtNewsListPic").filebox("clear");
				$("#txtNewsListPic").filebox("setText",data.data.newsListPic);
				$("#hidNewsListPic").val(data.data.newsListPic);
				$("#txtNewsListPosition").combobox("setValue",data.data.newsListPosition);
				$("#txtNewsStyle").combobox("setValue",data.data.newsStyle);
				$("#txtLink").textbox("setValue",data.data.link);
				$("#BackgroundColor").val(data.data.backgroundColor);
				$("#BackgroundOpacity").combobox("setValue", data.data.backgroundOpacity);
				$("#FontSize").combobox("setValue", data.data.fontSize);
				$("#FontWeight").combobox("setValue", data.data.fontWeight);
				$("#FontStyle").combobox("setValue", data.data.fontStyle);
				$("#FontColor").val(data.data.fontColor);
				$("#LineColor").val(data.data.lineColor);
				$("#IsShowMore").prop("checked", data.data.isShowMore);
				$("#MoreColor").val(data.data.moreColor);
				$("#ddlStatus").combobox("setValue",data.data.status);
				$("#txtSort").numberbox("setValue", data.data.sort);
				$("#txtRemark").textbox("setValue",data.data.remark);
				$("#detailWindow").window("open");
			}
		});
	}

	function saveData() {
		var isValid = $("#frmDetail").form("validate");
		var simEnd = $("#txtNewsListPic").filebox("getText");
		if (isValid) {
			if (simEnd!= "" && !/\.(gif|jpg|jpeg|png|GIF|JPG|PNG|JPEG)$/.test(simEnd)){
				common.showError("@Resources.MsgImgType");
				return false;
			} else {
				$.messager.confirm("@Resources.Save", "@Resources.CfmSave", function (r) {
					if (r) {
						var loading = layer.load(0,  {
							shade: [0.4,"#fff"]
						});

						$("#frmDetail").form({
							iframe: false,
							success: function (data) { }
						});

						switch ($("#hdnWindowType").val())
						{
							case "add":
								$("#frmDetail").form("submit", {
									url: "@Url.Action(nameof(ConferenceNewsListController.Create), nameof(ConferenceNewsListController).GetControllerName(),
										new { ConferenceId = Model.ConferenceId })",
									onSubmit: function (param) {
										param.random = Math.random();
									},
									success: function (data) {
										layer.close(loading);
										data = JSON.parse(data);
										if (data.result == "@ConstValues.AjaxFailResult") {
											common.showError(data.message);
										} else {
											common.showSuccess(data.message, true);
											$("#detailWindow").window("close");
											$("#dataGrid").datagrid("reload");
										}
									},
								});
								break;
							case "edit":
								$("#frmDetail").form("submit", {
									url: "@Url.Action(nameof(ConferenceNewsListController.Modify), nameof(ConferenceNewsListController).GetControllerName(),
										new { ConferenceId = Model.ConferenceId })",
									onSubmit: function (param) {
										param.random = Math.random();
									},
									success: function (data) {
										layer.close(loading);
										data = JSON.parse(data);
										if (data.result == "@ConstValues.AjaxFailResult") {
											common.showError(data.message);
										} else {
											common.showSuccess(data.message, true);
											$("#detailWindow").window("close");
											$("#dataGrid").datagrid("reload");
										}
									},
								});
								break;
						}
					}
				})
			}
		}
	};

	function searchData() {
		$("#dataGrid").datagrid("load", {
			selNewsListName: $("#selNewsListName").textbox("getValue"),
		});
	}
</script>
}